#!/bin/bash
set -e

while getopts  ":s:p:h" opts
do
	case  $opts  in
	s)
		sample_name=$OPTARG
		;;
	p)
		panel=$OPTARG
		;;
	h)
		echo `basename $0` "[-s sample_name] [-p panel] <in1.fq[.gz]> <in2.fq[.gz]>"
		exit 1
		;;
	\?)
		
		echo `basename $0` ': invalid option --' \?
		exit 1
		;;
	esac
done
shift $(($OPTIND - 1))

if [ -z "$2" ]; then
	echo `basename $0` "[-s sample_name] [-p panel] <in1.fq[.gz]> <in2.fq[.gz]>"
	exit 1
fi

if [ -z $panel ]; then
	interval=$data_path/intervals/1/b37.xx50_ph.bed
elif [ "panel" = "62" ]; then
	interval=$data_path/intervals/1/b37.xx50_ph.bed
elif [ "panel" = "14" ]; then
	interval=$data_path/intervals/1/jiechen_14_xx.bed
else 
	echo `basename $0` $@ : invalid panel
	exit 1
fi


. /mnt/ilustre/app/medical/tools/.var


if [ -z $sample_name ]; then
	sample_name=sample_test
fi



datee=`date +h%Hm%Ms%S_m%md%d_%y`
dir_name=${sample_name}_$datee
mkdir $dir_name
mv $log $dir_name
cd $dir_name

if
echo $1 |perl -n -e 'if(/^\//){exit 0;}else{exit 2;}'
then
cutadapt_yitong_ph.sh $1 $2
else
cutadapt_yitong_ph.sh ../$1 ../$2
fi

# cutadapt_yitong_ph.sh ../$1 ../$2

align2bam.sh -s $sample_name 1.1.cut.fastq 1.2.cut.fastq

$tools_path/summa.sh 1.sort.bam $interval

